// pages/movie/movie.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index:0,
    tabs:[
      {id:0,name:'热映',isActive:true},
      {id:1,name:'影院',isActive:false},
      {id:2,name:'待映',isActive:false},
    ],
    movieList :[
      {
        "movie_id": 20001,
        "cat_id": 1,
        "movie_name": "满江红",
        "movie_price": "￥40起",
        "movie_score": 9.5,
        "movie_time": "159min",
        "movie_small_pic": "https://img2.doubanio.com/view/photo/s_ratio_poster/public/p2887555071.webp",
        "movie_category": "悬疑/喜剧/剧情",
        "movie_shangying_time": "2023-01-22 09:00",
      },
      {
        "movie_id": 20002,
        "cat_id": 2,
        "movie_name": "熊出没·伴我熊“芯”",
        "movie_price": "￥40起",
        "movie_score": 9.3,
        "movie_time": "96min",
        "movie_small_pic": "https://bkimg.cdn.bcebos.com/pic/9a504fc2d5628535e5ddf8a4dfb961c6a7efcf1bc5a2?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UyNzI=,g_7,xp_5,yp_5",
        "movie_category": "动画/喜剧/科幻",
        "movie_shangying_time": "2023-01-22 09:00",
      },
      {
        "movie_id": 20003,
        "cat_id": 3,
        "movie_name": "流浪地球2",
        "movie_price": "￥40起",
        "movie_score": 9.3,
        "movie_time": "173min",
        "movie_small_pic": "https://bkimg.cdn.bcebos.com/pic/9825bc315c6034a85edfa89095455e540923dd54d8de?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UyNzI=,g_7,xp_5,yp_5",
        "movie_category": "科幻/冒险/灾难",
        "movie_shangying_time": "2023-01-22 09:00",
      },
      {
        "movie_id": 20004,
        "cat_id": 4,
        "movie_name": "深海",
        "movie_price": "￥40起",
        "movie_score": 9.1,
        "movie_time": "112min",
        "movie_small_pic": "https://bkimg.cdn.bcebos.com/pic/08f790529822720e0cf323c9499d1d46f21fbe097df3?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5",
        "movie_category": "奇幻/动画",
        "movie_shangying_time": "2023-01-22 09:00",
      },
      {
        "movie_id": 20005,
        "cat_id": 5,
        "movie_name": "中国乒乓",
        "movie_price": "￥40起",
        "movie_score": 9.4,
        "movie_time": "137min",
        "movie_small_pic": "https://img9.doubanio.com/view/photo/m/public/p2887599076.webp",
        "movie_category": "剧情/运动",
        "movie_shangying_time": "2023-02-17 09:00",
      },
      {
        "movie_id": 20006,
        "cat_id": 6,
        "movie_name": "不能流泪的悲伤",
        "movie_price": "￥40起",
        "movie_score": 9.0,
        "movie_time": "97min",
        "movie_small_pic": "https://bkimg.cdn.bcebos.com/pic/c83d70cf3bc79f3df8dcfec0c3f7da11728b461083bf?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxMTY=,g_7,xp_5,yp_5",
        "movie_category": "爱情",
        "movie_shangying_time": "2023-02-14 09:00",
      },
      {
        "movie_id": 20007,
        "cat_id": 7,
        "movie_name": "无名",
        "movie_price": "￥40起",
        "movie_score": 9.1,
        "movie_time": "128min",
        "movie_small_pic": "https://bkimg.cdn.bcebos.com/pic/79f0f736afc379310a5537a4b792a04543a98326bbba?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UyNzI=,g_7,xp_5,yp_5",
        "movie_category": "悬疑/动作/剧情",
        "movie_shangying_time": "2023-01-22 09:00",
      },
      {
        "movie_id": 20008,
        "cat_id": 8,
        "movie_name": "阿凡达·水之道",
        "movie_price": "￥40起",
        "movie_score": 9.1,
        "movie_time": "192min",
        "movie_small_pic": "https://img9.doubanio.com/view/photo/m/public/p2884182275.webp",
        "movie_category": "科幻/动作/冒险",
        "movie_shangying_time": "2022-12-16",
      },
      {
        "movie_id": 20009,
        "cat_id": 9,
        "movie_name": "黑豹2",
        "movie_price": "￥40起",
        "movie_score": 8.4,
        "movie_time": "161min",
        "movie_small_pic": "https://bkimg.cdn.bcebos.com/pic/eac4b74543a98226cffc8f34dfd4ae014a90f603bdd0?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxODA=,g_7,xp_5,yp_5",
        "movie_category": "动作/冒险",
        "movie_shangying_time": "2023-02-07",
      },
      {
        "movie_id": 20010,
        "cat_id": 10,
        "movie_name": "交换人生",
        "movie_price": "￥40起",
        "movie_score": 8.7,
        "movie_seen": 7797030,
        "movie_time": "110min",
        "movie_small_pic": "https://img1.doubanio.com/view/photo/m/public/p2886396440.webp",
        "movie_category": "喜剧/家庭",
        "movie_shangying_time": "2023-01-22 09:00",
      }
    ],
    movieToShow:[
      {
        
          "movie_id": 20004,
          "cat_id": 4,
          "movie_name": "蚁人与黄蜂女3：量子狂潮",
          "movie_price": "￥40起",
          "movie_score": 9.5,
          "movie_time": "159min",
          "movie_small_pic": "https://img2.doubanio.com/view/photo/s_ratio_poster/public/p2887555071.webp",
          "movie_category": "悬疑/喜剧/剧情",
          "movie_shangying_time": "2023-01-22 09:00",
        },
        {
          "movie_id": 23751,
          "cat_id": 11,
          "movie_name": "毒舌律师",
          "movie_price": "￥56起",
          "movie_score": 9.6,
          "movie_time": "133min",
          "movie_small_pic": "https://n.sinaimg.cn/sinakd20230106s/0/w2000h2800/20230106/a8a8-c08ea833c807ee1088cc232cfb32431b.jpg",
          "movie_category": "剧情/喜剧",
          "movie_shangying_time": "2023-02-24 09:00",
        },
        {
          "movie_id": 24751,
          "cat_id": 12,
          "movie_name": "保你平安",
          "movie_price": "￥99起",
          "movie_score": 9.7,
          "movie_time": "112min",
          "movie_small_pic": "https://p2.ssl.qhimgs1.com/sdr/400__/t018e5a05c793350698.jpg",
          "movie_category": "剧情/喜剧",
          "movie_shangying_time": "2023-03-10 09:00",
        },
        {
          "movie_id": 45751,
          "cat_id": 13,
          "movie_name": "龙马精神",
          "movie_price": "￥39起",
          "movie_score": 8.9,
          "movie_time": "110min",
          "movie_small_pic": "https://p2.ssl.qhimgs1.com/sdr/400__/t0163490ba4da859788.jpg",
          "movie_category": "剧情/喜剧/剧情",
          "movie_shangying_time": "2023-04-07 09:00",
        },
        {
          "movie_id": 45751,
          "cat_id": 14,
          "movie_name": "龙马精神",
          "movie_price": "￥39起",
          "movie_score": 8.9,
          "movie_time": "110min",
          "movie_small_pic": "https://p2.ssl.qhimgs1.com/sdr/400__/t0163490ba4da859788.jpg",
          "movie_category": "剧情/喜剧/剧情",
          "movie_shangying_time": "2023-04-07 09:00",
        },
        {
          "movie_id": 45751,
          "cat_id": 15,
          "movie_name": "龙马精神",
          "movie_price": "￥39起",
          "movie_score": 8.9,
          "movie_time": "110min",
          "movie_small_pic": "https://p2.ssl.qhimgs1.com/sdr/400__/t0163490ba4da859788.jpg",
          "movie_category": "剧情/喜剧/动作",
          "movie_shangying_time": "2023-04-07 09:00",
        },
        {
          "movie_id": 49851,
          "cat_id": 16,
          "movie_name": "断网",
          "movie_price": "￥45起",
          "movie_score": 9.0,
          "movie_time": "110min",
          "movie_small_pic": "https://p0.ssl.qhimgs1.com/sdr/400__/t01e78d9b04294c346a.jpg",
          "movie_category": "犯罪/动作/剧情",
          "movie_shangying_time": "2023-03-03 18:00",
        },
    ],
    cinema:[
      {
        "id":1,
        "name":"中影巨幕影城（欧亚商都店）",
        "address":"朝阳区红旗街工农大路欧亚商都10层",
        "price":"￥19.9起",
        "return":true,
        "dulby":false,
        "change":true,
        "child":false,
        "hugescreen":true,
        "snack":false
      },
      {
        "id":2,
        "name":"万达影城（高新活力汇店）",
        "address":"朝阳区华光街588号活力汇购物中心四楼",
        "price":"￥19.9起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":false
      },
      {
        "id":3,
        "name":"万达影城（栖乐荟广场IMAX店）",
        "address":"朝阳区博文路与学府街交汇处栖乐荟购物广场3楼万达影城",
        "price":"￥25起",
        "return":true,
        "dulby":false,
        "change":true,
        "child":false,
        "hugescreen":true,
        "snack":false
      },
      {
        "id":4,
        "name":"万达影城（红旗街IMAX店）",
        "address":"朝朝阳区红旗街万达广场4楼（省医院旁）",
        "price":"￥25起",
        "return":true,
        "dulby":false,
        "change":true,
        "child":false,
        "hugescreen":true,
        "snack":true
      },
      {
        "id":5,
        "name":"万达影城（欧亚新生活店）",
        "address":"朝阳区红旗街道延安大街99号欧亚新生活购物广场5F",
        "price":"￥25起",
        "return":true,
        "dulby":false,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":false
      },
      {
        "id":6,
        "name":"万达影城（力旺广场IMAX店）",
        "address":"朝阳区前进大街与繁荣路交汇（前进大街996号）力旺广场商业综合体三层",
        "price":"￥25起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":false,
        "hugescreen":true,
        "snack":false
      },
      {
        "id":7,
        "name":"长影电影院",
        "address":"朝阳区红旗街1118号（老长春电影制片厂院内）",
        "price":"￥28.5起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":true
      },
      {
        "id":8,
        "name":"吉视影城（居然世界里店）",
        "address":"朝阳区高新技术产业开发区硅谷大街7270居然世界里购物中心5层5001",
        "price":"￥30起",
        "return":true,
        "dulby":false,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":true
      },
      {
        "id":9,
        "name":"大地影院（长春這有山店）",
        "address":"朝阳区红旗街道红旗街959号这有山商场4F",
        "price":"￥35起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":true
      },
      {
        "id":10,
        "name":"恒大嘉凯影城绿洲店",
        "address":"朝阳区超然街与宜居路交汇恒大绿洲14号楼3层",
        "price":"￥25起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":false,
        "hugescreen":false,
        "snack":false
      },
      {
        "id":11,
        "name":"橙天国际影城（高新活力汇店）",
        "address":"朝阳区华光街588号活力汇F4层",
        "price":"￥19.9起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":true,
        "hugescreen":false,
        "snack":false
      },
      {
        "id":12,
        "name":"普泰影城",
        "address":"朝阳区向阳路856号富锋镇富锋购物中心二楼",
        "price":"￥21.9起",
        "return":true,
        "dulby":false,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":false
      },
      {
        "id":13,
        "name":"恒大嘉凯影城（名都店）",
        "address":"朝阳区光谷大街与超达大路交汇西行500米路北",
        "price":"￥20起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":true,
        "hugescreen":false,
        "snack":false
      },
      {
        "id":14,
        "name":"吉大巨幕影城",
        "address":"朝阳区修正路与致远街交汇吉大院内文化活动中心五楼",
        "price":"￥19.9起",
        "return":true,
        "dulby":true,
        "change":true,
        "child":true,
        "hugescreen":true,
        "snack":true
      },
    ]
    // region: ['吉林省', '长春市', '朝阳区'], //城市选择器
    // cityId: 116, //城市ID
    // items: '', //电影列表
    // customItem: '选择城市',
    // images: []
  },
  /**
   * 生命周期函数--监听页面加载
   */
  toMovieDetail(e){
    console.log(e.currentTarget.dataset.id);
    
    wx.navigateTo({
      url: '../movie_detail/movie_detail?movie_index='+this.index
    })
  },
  onLoad(option){
    let tabs=JSON.parse(option.tabs)
  },
   
  onReachBottom(){
    wx.showToast({
      title: '已经到底啦！',
    })
  },
  //事件处理函数
  // bindViewTap: function () {
  //   wx.navigateTo({
  //     url: '../logs/logs'
  //   })
  // },
  // bindRegionChange: function (e) {
  //   const that = this
  //   console.log('picker发送选择改变，携带值为', e.detail.value)
  //   this.setData({
  //     region: e.detail.value
  //   })
  //   wx.request({
  //     url: 'https://openapi.meituan.com/poi/city', //获取城市ID
  //     method: 'GET',
  //     data: {},
  //     // header: {
  //     //   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'
  //     // },
  //     success: function (res) {
  //       console.log(res.data);
  //       console.log(that.data.region[1])
  //       for (var k in res.data.data) {
  //         if (that.data.region[1] == res.data.data[k].name + '市') {
  //           console.log(res.data.data[k].id)
  //           that.setData({
  //             cityId: res.data.data[k].id
  //           })
  //         }
  //       }
        
  //     }
  //   })
  //   app.globalData.cityId=this.data.cityId;
    
  //   this.getMoviceByCity();



  // },
  // getMoviceByCity(callback) {
  //   var that = this
  //   wx.request({
  //     url: 'https://m.maoyan.com/ajax/movieOnInfoList?ci='+that.data.cityId,
  //     success(res) {
  //       for (var i in res.data.movieList) {
  //         res.data.movieList[i].img = res.data.movieList[i].img.replace(/w.h/g, "372.550");
  //         res.data.movieList[i].star=res.data.movieList[i].star.replace(/,/g, " / ")
  //         that.data.images.push(res.data.movieList[i].img)
  //       }
  //       console.log(res.data.movieList);
  //       that.setData({
  //         images:that.data.images,
  //         items:res.data.movieList
  //       })
  //     }
  //   })
  // },
  // toMoviceDetail(e){
  //   console.log(e.currentTarget.dataset.id);
  //   wx.navigateTo({
  //     url: '../moviceDetail/moviceDetail?id='+e.currentTarget.dataset.id,
  //   })
  // },

  // onLoad: function () {
  //   console.log('onLoad')
  //   console.log(app.globalData.userInfo)
  //   this.getMoviceByCity();
  //   var that = this
  //   //调用应用实例的方法获取全局数据
  //   app.getUserInfo(function (userInfo) {
  //     //更新数据
  //     that.setData({
  //       userInfo: userInfo
  //     })
  //   })

   

  // },
  // toBuyTicks(e) {
  //   console.log(e);
  //   var movieId = e.currentTarget.dataset.info.id;
  //   var rt=e.currentTarget.dataset.info.rt;
  //   var movieName=e.currentTarget.dataset.info.nm;
  //   wx.navigateTo({
  //     url:`../cinema/cinemaSelect/cinemaSelect?movieId=${movieId}&rt=${rt}&movieName=${movieName}`
  //   })
  // },
  

  // /**
  //  * 生命周期函数--监听页面初次渲染完成
  //  */
  // onReady() {

  // },

  // /**
  //  * 生命周期函数--监听页面显示
  //  */
  // onShow() {

  // },

  // /**
  //  * 生命周期函数--监听页面隐藏
  //  */
  // onHide() {

  // },

  // /**
  //  * 生命周期函数--监听页面卸载
  //  */
  // onUnload() {

  // },

  // /**
  //  * 页面相关事件处理函数--监听用户下拉动作
  //  */
  // onPullDownRefresh() {

  // },

  // /**
  //  * 页面上拉触底事件的处理函数
  //  */
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage() {

  // },

  handleItemChange(e){
    const {index}=e.detail;
    let {tabs}=this.data;
    tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false);
    this.setData({
      tabs
    })
  },
  MovieInfo:{}  , 
  //点击添加喜欢
  praiseThis(){
    //1、获取喜欢缓存中的数组
    let like = wx.getStorageSync("like")||[] ;   //获取到的为空，则将数组[]赋值给like
    //2、判断对象是否在数组中
    let index = like.findIndex(v=>v.movie_id===this.MovieInfo.movie_id);
    this.setData({
      
    });
    if(index===-1){
      like.push(this. MovieInfo)
    }
    //5、重新添加回缓存中
    wx.setStorageSync("like", like) ; 
    //6、弹窗提示
    wx.showToast({
      title: '点赞成功',
      icon: 'success' ,
      //防止手抖疯狂点击按钮，默认情况会在一段时间之后才可以再次点击按钮
      mask:true  
    })
  }

})